package com.easyedu.teacher.controller;

import com.easyedu.core.entity.po.OpenCourse;
import com.easyedu.core.entity.po.StudentSelect;
import com.easyedu.core.entity.po.Teacher;
import com.easyedu.core.util.R;
import com.easyedu.teacher.entity.dto.request.ReqCommitGrade;
import com.easyedu.teacher.service.TeacherService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author lmr</ br>
 * 教师管理
 **/
@Validated
@RequestMapping("/teacher")
@RestController
public class TeacherController {

    private final TeacherService teacherService;

    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    /**
     * 功能描述:获取教师信息
     *
     * @param teacherNumber 1 教师编号
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/information")
    public R information(@RequestParam Long teacherNumber) {
        Teacher teacherInformation = teacherService.getInformation(teacherNumber);
        return R.ok().data(teacherInformation);
    }

    /**
     * 功能描述:获取教师所教课程
     *
     * @param teacherId    1 教师id
     * @param openYear     2 开放年份
     * @param openSemester 3 开放学期 semester
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/course/teach")
    public R getTeachCourse(@RequestParam Long teacherId, @RequestParam int openYear, @RequestParam String openSemester) {
        List<OpenCourse> openCourses = teacherService.getTeachCourse(teacherId, openYear, openSemester);
        return R.ok().data(openCourses);
    }

    /**
     * 功能描述: 获取课程成绩
     *
     * @param openCoursesId 1 开放课程唯一id
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/course/grade")
    public R getCourseGrade(@RequestParam Long openCoursesId) {
        List<StudentSelect> courseGrade = teacherService.getCourseGrade(openCoursesId);
        return R.ok().data(courseGrade);
    }

    /**
     * 功能描述: 提交学生成绩
     *
     * @param reqCommitGrades 1 提交成绩集
     * @return : com.easyedu.api.util.R
     **/
    @Transactional
    @PostMapping("/course/grade")
    public R createGrade(@RequestBody @Valid List<ReqCommitGrade> reqCommitGrades) {
        int number = teacherService.createGrade(reqCommitGrades);
        return R.ok().message(number + "门成绩提交成功");
    }


}
